package com.ct.controller.shops;


import com.ct.application.commons.vo.StatusRequest;
import com.ct.application.shops.model.po.ShopsAddPO;
import com.ct.application.shops.model.po.ShopsQueryPO;
import com.ct.application.shops.model.po.ShopsUpdatePO;
import com.ct.application.shops.model.vo.ShopsListVO;
import com.ct.application.shops.model.vo.ShopsVO;
import com.ct.application.shops.service.ShopsService;
import com.ct.commons.BaseController;
import com.ct.commons.annotation.ApiLog;
import com.ct.commons.annotation.HasAdmin;
import com.ct.commons.annotation.PermissionApi;
import com.ct.commons.aspect.limiter.AccessIpLimiter;
import com.ct.repository.commons.PageUtils;
import jakarta.annotation.Resource;
import jakarta.validation.Valid;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 管理后台-门店模块
 *
 * @author system
 * @since 2024-03-05
 */
@RestController
@PermissionApi(title = "门店分类模块",path="/api/v1/shops",code = "H1000",sorted = 3)
public class ShopsController extends BaseController {

    @Resource
    private ShopsService shopsService;


    /**
     * 获取门店列表数据
     */
    @PostMapping("/shops/getShopsList")
    @PermissionApi(title = "门店列表数据",path="/api/v1/shops/getShopsList",code = "H1001",sorted = 1)
    public PageUtils<ShopsVO> getShopsList(@Valid @RequestBody ShopsQueryPO queryPO) {
        return shopsService.getShopsList(queryPO);
    }


    /**
     * 获取门店列表(用于添加商品)
     */
    @PostMapping("/shops/list")
    @PermissionApi(title = "获取门店列表",path="/api/v1/shops/list",code = "H1002",sorted = 2)
    public List<ShopsListVO> getShopsLists() {
        return shopsService.findShopsList();
    }


    /**
     * 根据id查询门店
     */
    @PostMapping("/shops/get/{id}")
    @PermissionApi(title = "根据id查询门店",path="/api/v1/shops/get/{id}",code = "H1003",sorted =3)
    public ShopsVO getShopsById(@PathVariable("id")Long id){
        return shopsService.getShopsById(id);
    }


    /**
     * 新增门店
     */
    @PostMapping("/shops/add")
    @HasAdmin
    @AccessIpLimiter
    @ApiLog("添加店铺")
    @PermissionApi(title = "添加店铺",path="/api/v1/shops/add",code = "H1004",sorted = 4)
    public Boolean add(@Valid @RequestBody ShopsAddPO po){
        return shopsService.add(po);
    }



    /**
     * 修改门店
     */
    @PostMapping("/shops/update")
    @HasAdmin
    @AccessIpLimiter
    @ApiLog("修改门店")
    @PermissionApi(title = "修改门店",path="/api/v1/shops/update",code = "H1005",sorted = 5)
    public Boolean update(@Valid @RequestBody ShopsUpdatePO po){
        return shopsService.update(po);
    }



    /**
     * 删除门店
     */
    @PostMapping("/shops/delete/{id}")
    @HasAdmin
    @AccessIpLimiter
    @ApiLog("删除门店")
    @PermissionApi(title = "删除门店",path="/api/v1/delete/{id}",code = "H1006",sorted = 6)
    public Boolean delete(@PathVariable("id")Long id) {
        return shopsService.delete(id);
    }


    /**
     * 修改营业状态
     *
     * @param id              主键
     * @param operatingStatus 是否营业 1是 0否
     */
    @GetMapping("/shops/updateOperatingStatus")
    @HasAdmin
    @AccessIpLimiter
    @ApiLog("修改营业状态")
    @PermissionApi(title = "修改营业状态",path="/api/v1/shops/updateOperatingStatus",code = "H1007",sorted = 7)
    public boolean updateOperatingStatus(@RequestParam Long id,  @RequestParam Integer operatingStatus) {
        return shopsService.updateOperatingStatus(id, operatingStatus);
    }

    @PostMapping("/shops/update/status")
    @HasAdmin
    @AccessIpLimiter
    @ApiLog("修改状态")
    @PermissionApi(title = "修改状态",path="/api/v1/shops/update/status",code = "H1008",sorted = 8)
    public Boolean updateStatus(@RequestBody StatusRequest statusRequest) {
        return shopsService.updateStatus(statusRequest);
    }
}

